<!--  -->
<template>
  <div class="login">
    <img src="../../assets/imgs/bg.jpg">
    <div class="login_form-wrap">
      <img class="login-bg" src="../../assets/imgs/login_bg@2x.png">
      <!-- 左侧banner -->
      <div class="login_form-left">
        <img class="login-left-bg" src="../../assets/imgs/login_left_bg@2x.png">

      </div>
      <div class="login_form-right">
        <div class="right-wrap">
          <div class="top">
            <p>诺博智慧医院统一管理平台</p>
          </div>
          <div class="form">
            <a-form :model="formState" name="basic" :label-col="{ span: 8 }" :wrapper-col="{ span: 16 }"
              autocomplete="off" @finish="onFinish" @finishFailed="onFinishFailed">
              <a-form-item label="用户名" name="account" :rules="[{ required: true, message: '用户名不能为空!' }]">
                <a-input v-model:value="formState.account" />
              </a-form-item>

              <a-form-item label="密码" name="password" :rules="[{ required: true, message: '用户名不能为空!' }]">
                <a-input-password v-model:value="formState.password" />
              </a-form-item>
              <a-form-item :wrapper-col="{ offset: 8, span: 16 }">
                <a-button type="primary" html-type="submit">登录</a-button>
              </a-form-item>
            </a-form>
          </div>
        </div>
      </div>
    </div>

  </div>
</template>

<script setup lang='ts'>
import { message } from 'ant-design-vue';
import { reactive } from 'vue'
import { userLogin } from '../../api/login'
import router from '../../router';
interface FormState {
  account: string;
  password: string;
}
const loginImgList: any[] = [
  {
    url: '../../assets/imgs/hospital@2x.png',
    alt: '门急诊药品管理'
  },
  {
    url: '../../assets/imgs/operation@2x.png',
    alt: '手术室药品管理'
  },
  {
    url: '../../assets/imgs/intervention@2x.png',
    alt: '介入室耗材管理'
  },
  {
    url: '../../assets/imgs/disease@2x.png',
    alt: '病区耗材管理'
  }
]
const formState = reactive<FormState>({
  account: '',
  password: '',
});
// 登录的逻辑
const onFinish = (values: Admin) => {
  console.log('Success:', values);
  userLogin(values).then(res => {
    if (res.result) {
      sessionStorage.setItem('token', res.data.token)
      router.push('/user')
      message.success('登录成功')
    } else {
      message.error(res.message)
    }
  })
};

const onFinishFailed = (errorInfo: any) => {
  console.log('Failed:', errorInfo);
};
</script>
<style scoped lang="less">
.login {
  width: 100%;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;

  >img {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
  }

  .login_form-wrap {
    width: 1120px;
    height: 640px;
    background: rgba(255, 255, 255, 1);
    box-shadow: -4px 4px 14px 0px rgba(122, 122, 122, 0.38);
    border-radius: 6px;
    position: relative;
    opacity: .85;

    .login-bg {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      z-index: 2;

    }
  }

  .login_form-left {
    width: 446px;
    height: 100%;
    float: left;
    position: relative;
    background: #f5faff;
    border-top-left-radius: 16px;
    border-bottom-left-radius: 16px;
    z-index: 1;

    .login-left-bg {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: auto;
    }

    .ant-carousel {
      margin-top: 45%;

      .slick-initialized {
        .slick-list {
          .slick-slide {
            display: flex;
            align-items: center;
            justify-content: center;

            .img-desc {
              text-align: center;
              font-weight: 500;
              color: rgba(0, 47, 110, 0.4);
              font-size: 28px;
            }

            img {
              width: 210px;
              height: auto;
            }
          }
        }
      }

      .slick-dot {
        bottom: -40px;

        li.slick-active {
          button {
            width: 12px;
            height: 12px;
            background-color: #002f6e;
          }
        }

        li {
          margin: 0 6px;

          button {
            width: 12px;
            height: 12px;
            background-color: white;
            border: 2px solid #002f6e;
            border-radius: 16px;
          }
        }
      }
    }

    img {
      height: 640px;
    }
  }

  .login_form-right {
    width: 663px;
    height: 640px;
    display: inline-block;
    position: absolute;
    top: 0;
    right: 0;
    z-index: 3;

    .right-wrap {
      width: 456px;
      position: absolute;
      left: 50%;
      transform: translateX(-50%);
      top: 111px;

      .top {
        text-align: left;
        font-size: 32px;
        color: rgb(126, 126, 126);
      }
    }

  }
}
</style>